package com.etc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.service.impl.AnnouncementServiceImpl;
import com.etc.entity.Announcement;

import com.etc.service1.AnnouncementService;



/**
 * Servlet implementation class AddAnnouncementServlet
 */
@WebServlet("/AddAnnouncementServlet")
public class AddAnnouncementServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddAnnouncementServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username=request.getParameter("username");
		String title=request.getParameter("title");
		String content=request.getParameter("content");
		String sf=request.getParameter("sf");
		AnnouncementService an=new AnnouncementServiceImpl();
		Boolean result=false;
		Announcement announcement=new Announcement(0, username,title,content);
	    result=an.addAnnouncement(announcement);
		if(result) {
                  System.out.println("添加成功!");
		}else {
			 System.out.println("添加失败!");
			 System.out.println(username);
		}
		response.sendRedirect("ListAnnouncementServlet?sf=admin");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
